﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using System.Drawing;
using SkypePXP;
using PLAYXPERT.Windows;
using PLAYXPERT.Interfaces;
using BackLib;
using BackLib.Networking;
using System.Threading;
using System.Linq;

namespace PLAYXPERT.Widgets
{
    public partial class MainForm : PXPForm
    {
        ImageList statusImages = new ImageList();
        SettingsPage settingsPage;
        Settings settings;
        Hook hook;
        SkypeWrapper skypeWrapper;
        DirectCapture directCapture;
        ICore iCore;
        Color mainBackColor = Color.FromArgb(6, 20, 30);
        List<ChatForm> chatForms = new List<ChatForm>();
        AddPeople addPeople;
        CallForm callForm;
        static string MoodEmptyText = "Write a message here for your friends to see.";
        bool ActiveCallExpanded = true;
        ControlStatus controlStatus;

        public MainForm(PLAYXPERT.Interfaces.ICore iCore)
        {
            InitializeComponent();
            DoubleBuffered = true;
            this.iCore = iCore;

            //Create Core Objects
            settings = new Settings(iCore);
            hook = new Hook((Settings)settings);
            settingsPage = new SettingsPage(settings, hook);
            controlStatus = new ControlStatus(labelStatusLabel);

            //Create Game Trigger
            iCore.GetAutomationEngine().EventTriggered += new PXPEventHandler(AutoEngine_EventTriggered);

            //Add Status Images
            statusImages.Images.Add(SkypePXP.Properties.Resources.Online);
            statusImages.Images.Add(SkypePXP.Properties.Resources.Busy);
            statusImages.Images.Add(SkypePXP.Properties.Resources.Away);
            statusImages.Images.Add(SkypePXP.Properties.Resources.Blocked);
            statusImages.Images.Add(SkypePXP.Properties.Resources.Invisible);
            statusImages.Images.Add(SkypePXP.Properties.Resources.s4pg);

            tabPage5.Controls.Add(settingsPage.panelSettingsPanel);
            yaTabControl1.SelectedIndex = 0;

            skypeWrapper = new SkypeWrapper();
            callForm = new CallForm(skypeWrapper, statusImages, this);
            skypeWrapper.CurrentUserMoodUpdated += new SkypeWrapper.CurrentUserMoodUpdatedHandler(skypeWrapper_CurrentUserMoodUpdated);
            skypeWrapper.CurrentUserStatusUpdated += new SkypeWrapper.CurrentUserStatusUpdatedHandler(skypeWrapper_CurrentUserStatusUpdated);
            skypeWrapper.UsersListed += new SkypeWrapper.UsersListedHandler(skypeWrapper_UsersListed);
            skypeWrapper.UserUpdated += new SkypeWrapper.UserUpdatedHandler(skypeWrapper_UserUpdated);
            skypeWrapper.ChatUpdated += new SkypeWrapper.ChatUpdatedHandler(skypeWrapper_ChatUpdated);
            skypeWrapper.ChatsListed += new SkypeWrapper.ChatsListedHandler(skypeWrapper_ChatsListed);
            skypeWrapper.CallUpdated += new SkypeWrapper.CallUpdatedHandler(skypeWrapper_CallUpdated);
            skypeWrapper.CallsListed += new SkypeWrapper.CallsListedHandler(skypeWrapper_CallsListed);
            skypeWrapper.MessageReceived += new SkypeWrapper.MessageReceivedHandler(skypeWrapper_MessageReceived);
            skypeWrapper.MuteChanged += new SkypeWrapper.MuteChangedHandler(skypeWrapper_MuteChanged);
            skypeWrapper.ConnectToSkype();
            
            splitContainerMain.Panel1.Controls.Add(callForm.panelParent);
            callForm.AddPeople += new CallForm.AddPeopleHandler(callForm_AddPeople);

            addPeople = new AddPeople(skypeWrapper);

            controlStatus.CreateEvents(new Control[] { this, callForm });

            dataGridViewContacts.Focus();

            SkinControls();

            //Create Hook Event Handlers
            hook.Toggle += new Hook.ToggleHandler(hook_Toggle);
            hook.ScreenCap += new Hook.ScreenCapHandler(ScreenCap);

            UpdateMuteDisplay(skypeWrapper.MuteStatus);

            CreateMinimalModeEvents();
        }

        void skypeWrapper_MuteChanged(bool muted)
        {
            UpdateMuteDisplay(muted);
        }

        void CreateMinimalModeEvents()
        {
            this.Resize += new EventHandler(MainForm_Resize);
        }

        void MainForm_Resize(object sender, EventArgs e)
        {
            yaTabControl1.TabChanged += new EventHandler(yaTabControl1_TabChanged);
        }

        void yaTabControl1_TabChanged(object sender, EventArgs e)
        {
            switch (yaTabControl1.SelectedIndex)
            {
                case 0:
                    this.Height = specialSize(dataGridViewContacts.Height);
                    break;
                case 1:
                    this.Height = specialSize(dataGridViewS4PG.Height);
                    break;
                case 2:
                    break;
                case 3:
                    break;
                case 4:
                    break;
                case 5:
                    this.Height = 1050;
                    break;
            }
            //this.Width = 350;

            if (this.Width < 350)
            {
                for (int i = 0; i < yaTabControl1.Controls.Count; i++)
                {
                    try
                    {
                        CustomTabControl.YaTabPage page = (CustomTabControl.YaTabPage)yaTabControl1.Controls[i];
                        page.Text = page.Text.Remove(page.Text.Length - 1, 1);
                    }
                    catch { }
                }
            }
        }

        int specialSize(int addAmount)
        {
            int newHeight = 65 + splitContainerMain.Top + splitContainerMain.SplitterDistance + addAmount;
            return newHeight > 380 ? 380 : newHeight;
        }

        #region AddPeople Form

        void callForm_AddPeople(bool isGroup, int ID)
        {
            addPeople.StartShow(dataGridViewContacts);
            DialogResult result = addPeople.ShowDialog();
            if (result == DialogResult.OK)
            {
                List<string> userHandles = new List<string>();
                foreach (SKYPE4COMLib.User user in addPeople.users)
                {
                    userHandles.Add(user.Handle);
                }
                skypeWrapper.AddPeopleToCall(isGroup, ID, userHandles.ToArray());
            }
            tabPage1.Controls.Add(dataGridViewContacts);
        }

        void newChatForm_AddPeople(SKYPE4COMLib.Chat chat)
        {
            addPeople.StartShow(dataGridViewContacts);
            DialogResult result = addPeople.ShowDialog();
            if (result == DialogResult.OK)
            {
                chat.AddMembers(addPeople.users);
            }
            tabPage1.Controls.Add(dataGridViewContacts);
        }

        #endregion

        #region Calls

/////////////////////////////// AUTOMUTE ON AWAY //////////////////////////////////////////////////////////////////////////

        void skypeWrapper_CallsListed(SKYPE4COMLib.CallCollection calls)
        {
            List<int> conf_IDs = new List<int>();
            foreach (SKYPE4COMLib.Call call in calls)
            {
                if (!conf_IDs.Contains(call.ConferenceId) || call.ConferenceId == 0)
                {
                    conf_IDs.Add(call.ConferenceId);
                    bool groupCall = skypeWrapper.IsGroupCall(call);
                    SetRowCall(GetCallRowByID(groupCall ? call.ConferenceId : call.Id), call, groupCall, true);
                }
            }
            ActiveCallPanelUpdate();
        }

        void DatagridViewCallRemoveRow(DataGridViewRow row)
        {
            dataGridViewCalls.Rows.Remove(row);
            ((DurationTimer)row.Cells[3].Tag).Dispose();
            row.Dispose();
        }

        private void holdToolStripMenuItem_Click(object sender, EventArgs e)
        {
            callForm.buttonToggleHold.PerformClick();
        }

        private void endCallToolStripMenuItem_Click(object sender, EventArgs e)
        {
            callForm.buttonEndCall.PerformClick();
        }

        private void addPeopleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            callForm.buttonAddPeople.PerformClick();
        }

        private void dataGridViewCalls_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
        {
            ActiveCallPanelUpdate();
        }

        private void dataGridViewCalls_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            ActiveCallPanelUpdate();
            holdToolStripMenuItem.Text = callForm.buttonToggleHold.Text;
        }

        void skypeWrapper_CallUpdated(SKYPE4COMLib.Call call)
        {
            bool groupCall = skypeWrapper.IsGroupCall(call);
            int f = call.Id;
            DataGridViewRow row = GetCallRowByID(groupCall ? call.ConferenceId : call.Id);
            if ((!groupCall && skypeWrapper.GetCallStatusFriendly(call) == SkypeWrapper.CallStatusFriendly.CallEnded) || groupCall && skypeWrapper.ConferenceDead(call))
            {
                DatagridViewCallRemoveRow(row);
                return;
            }
            SetRowCall(row, call, groupCall, false);
        }

        private void ActiveCallPanelUpdate()
        {
            if (dataGridViewCalls.SelectedRows.Count == 1)
            {
                callForm.DisplayNewCall(dataGridViewCalls.SelectedRows[0]);
                callForm.TriggerExpand();
            }
            else if (dataGridViewCalls.Rows.Count != 0)
            {
                dataGridViewCalls.Rows[0].Selected = true;
                callForm.DisplayNewCall(dataGridViewCalls.SelectedRows[0]);
                callForm.TriggerExpand();
            }
            else callForm.TriggerCollapse();
        }

        private void dataGridViewCalls_Click(object sender, EventArgs e)
        {
            ActiveCallPanelUpdate();
        }

        private DataGridViewRow GetCallRowByID(int ID)
        {
            foreach (DataGridViewRow row in dataGridViewCalls.Rows)
            {
                if ((int)row.Tag == ID)
                    return row;
            }
            DataGridViewRow newRow = new DataGridViewRow();

            return NewCallRow(ID);
        }

        public class DurationTimer : IDisposable
        {
            public System.Windows.Forms.Timer TheTimer;
            public DataGridViewTextBoxCell Cell;
            private int Duration;
            public Label LabelToUpdate;
            private DataGridViewRow Row;

            public DurationTimer(DataGridViewTextBoxCell cell, int duration, DataGridViewRow row, Label label)
            {
                Duration = duration + 1;
                Cell = cell;
                Row = row;
                LabelToUpdate = label;
                TheTimer = new System.Windows.Forms.Timer();
                TheTimer.Tick += new EventHandler(TheTimer_Tick);
                TheTimer.Interval = 1000;
                TheTimer.Start();
            }

            void TheTimer_Tick(object sender, EventArgs e)
            {
                Duration++;
                string durationText = GetDurationText;
                if (Row.Selected) LabelToUpdate.Text = durationText;
                Cell.Value = durationText;
            }

            public string GetDurationText
            {
                get
                {
                    return new TimeSpan(0, 0, Duration).ToString();
                }
            }

            public void Dispose()
            {
                TheTimer.Dispose();
            }

        }

        private void SetRowCall(DataGridViewRow row, SKYPE4COMLib.Call call, bool groupCall, bool createTimer)
        {
            DataGridViewTextBoxCell statusIndexCell = new DataGridViewTextBoxCell();
            statusIndexCell.Value = groupCall;
            statusIndexCell.Tag = skypeWrapper.GetCallMembers(call);
            DataGridViewImageCell statusImageCell = new DataGridViewImageCell();
            statusImageCell.Value = SkypePXP.Properties.Resources.ResourceManager.GetObject(groupCall ? "GroupCall" : skypeWrapper.GetCallStatusFriendly(call).ToString());
            DataGridViewTextBoxCell displayNameCell = new DataGridViewTextBoxCell();
            displayNameCell.Value = skypeWrapper.GetCallName((List<SKYPE4COMLib.User>)statusIndexCell.Tag);
            DataGridViewTextBoxCell moodTextCell = new DataGridViewTextBoxCell();
            moodTextCell.Style.ForeColor = Color.LightGreen;
            if (moodTextCell.Tag == null)
                moodTextCell.Tag = new DurationTimer(moodTextCell, call.Duration, row, callForm.labelCallTimer);
            try
            {
                row.Cells[0] = statusIndexCell;
                row.Cells[1] = statusImageCell;
                row.Cells[2] = displayNameCell;
                row.Cells[3] = moodTextCell;
            }
            catch
            {
                row.Cells.AddRange(new DataGridViewCell[] { statusIndexCell, statusImageCell, displayNameCell, moodTextCell });
            }
            ActiveCallPanelUpdate();
        }

        private DataGridViewRow NewCallRow(int ID)
        {
            DataGridViewRow newRow = new DataGridViewRow();
            newRow.Tag = ID;
            //newRow.Selected = true;
            dataGridViewCalls.Rows.Insert(0, newRow);
            return dataGridViewCalls.Rows[0];

        }

        #endregion

        #region ChatForm

        private ChatForm ChatFormFromName(string name)
        {
            foreach (ChatForm chatForm in chatForms)
            {
                if (chatForm.ChatName == name)
                {
                    return chatForm;
                }
            }
            return null;
        }

        private ChatForm ChatFormFromChat(SKYPE4COMLib.Chat chat)
        {
            foreach (ChatForm chatForm in chatForms)
            {
                if (chatForm.ChatName == chat.Name)
                {
                    return chatForm;
                }
            }
            ChatForm newChatForm = new ChatForm(chat, skypeWrapper, iCore, statusImages);
            newChatForm.PopIn += new ChatForm.PopInHandler(newChatForm_PopIn);
            newChatForm.AddPeople += new ChatForm.AddPeopleHandler(newChatForm_AddPeople);
            chatForms.Add(newChatForm);
            return newChatForm;
        }

        void newChatForm_PopIn(string chatName)
        {
            GetChatRowByName(chatName).Selected = true;
            PopInChat(GetChatRowByName(chatName));
        }

        private void PopInChat(DataGridViewRow row)
        {
            dataGridViewConversations.SelectedRows[0].Selected = false;
            row.Selected = true;
            splitContainerConversations.Panel2.Controls.Clear();
            ChatForm cf = ChatFormFromName(row.Tag.ToString());
            splitContainerConversations.Panel2.Controls.Add(cf.GetSplitContainer);
            cf.Visible = false;
            splitContainerConversations.Panel2.Controls[0].Dock = DockStyle.Fill;
            SetCellActive((DataGridViewImageCell)row.Cells[2], false);
        }

        #endregion

        #region Conversations

        void skypeWrapper_MessageReceived(SKYPE4COMLib.ChatMessage message)
        {
            DataGridViewRow row = GetChatRowByName(message.Chat.Name);
            SetRowConversationChat(row, message.Chat, !row.Selected);
            ChatFormFromChat(message.Chat).UpdateMessages(message);
        }

        public void CreateNewChat(string[] handles)
        {
            yaTabControl1.SelectedIndex = 2;
            SKYPE4COMLib.Chat chat = skypeWrapper.CreateNewChat(handles);
            SetRowConversationChat(GetChatRowByName(chat.Name), chat, false);
            ChatFormFromChat(chat);
            PopInChat(GetChatRowByName(chat.Name));
        }

        void skypeWrapper_ChatsListed(SKYPE4COMLib.ChatCollection users)
        {
            foreach (SKYPE4COMLib.Chat chat in users)
            {
                SetRowConversationChat(GetChatRowByName(chat.Name), chat, false);
                ChatFormFromChat(chat);
            }
        }

        void skypeWrapper_ChatUpdated(SKYPE4COMLib.Chat chat)
        {
            DataGridViewRow row = GetChatRowByName(chat.Name);
            SetRowConversationChat(row, chat, false);
            ChatFormFromChat(chat).UpdateChat(chat);
        }

        private void dataGridViewConversations_Click(object sender, EventArgs e)
        {
            PopInChat(dataGridViewConversations.SelectedRows[0]);
        }

        private void SetCellActive(DataGridViewImageCell cell, bool active)
        {
            if (active)
                cell.Value = SkypePXP.Properties.Resources.Active;
            else
                cell.Value = SkypePXP.Properties.Resources.Empty;
        }

        private void SetRowConversationChat(DataGridViewRow row, SKYPE4COMLib.Chat chat, bool makeActive)
        {
            SetRowConversation(row, SkypePXP.Properties.Resources.Busy, skypeWrapper.GetChatName(chat), chat.Name, makeActive);
        }

        private void SetRowConversation(DataGridViewRow row, Bitmap cell1, string cell2, string tag, bool makeActive)
        {
            DataGridViewImageCell statusImageCell = new DataGridViewImageCell();
            statusImageCell.Value = cell1;

            DataGridViewTextBoxCell displayNameCell = new DataGridViewTextBoxCell();
            displayNameCell.Value = cell2;

            DataGridViewImageCell activeCell = new DataGridViewImageCell();
            SetCellActive(activeCell, makeActive);

            row.Tag = tag;
            try
            {
                row.Cells[0] = statusImageCell;
                row.Cells[1] = displayNameCell;
                row.Cells[2] = activeCell;
            }
            catch
            {
                row.Cells.AddRange(new DataGridViewCell[] { statusImageCell, displayNameCell, activeCell });
            }

            dataGridViewConversations.Height = (dataGridViewConversations.Rows.Count) * 19;
            splitContainerConversations.SplitterDistance = dataGridViewConversations.Height + 10;
        }

        private DataGridViewRow GetChatRowByName(string name)
        {
            foreach (DataGridViewRow row in dataGridViewConversations.Rows)
            {
                if (row.Tag.ToString() == name)
                {
                    return row;
                }
            }
            return NewChatRow;
        }

        private DataGridViewRow NewChatRow
        {
            get
            {
                dataGridViewConversations.Rows.Insert(0, new DataGridViewRow());
                return dataGridViewConversations.Rows[0];
            }
        }

        #endregion

        #region Conversations Toolstrip

        #endregion

        #region Current User

        void skypeWrapper_CurrentUserStatusUpdated(SkypeWrapper.OnlineStatusFriendly status)
        {
            if (comboBoxOnlineStatus.SelectedIndex == -1 || comboBoxOnlineStatus.SelectedItem.ToString() != status.ToString())
            {
                comboBoxOnlineStatus.SelectedItem = status.ToString();
            }
        }

        void skypeWrapper_CurrentUserMoodUpdated(string mood)
        {
            if (mood == "") textBoxMood.Text = MoodEmptyText;
            else textBoxMood.Text = mood;
        }


        private void comboBoxOnlineStatus_SelectedIndexChanged(object sender, EventArgs e)
        {
            skypeWrapper.UpdateStatus((SkypeWrapper.OnlineStatusFriendly)Enum.Parse(typeof(SkypeWrapper.OnlineStatusFriendly), comboBoxOnlineStatus.SelectedItem.ToString()));
        }

        private void UpdateMood()
        {
            if (textBoxMood.Text == MoodEmptyText)
            {
                skypeWrapper.UpdateMood("");
            }
            else skypeWrapper.UpdateMood(textBoxMood.Text);
            if (textBoxMood.Text == "")
            {
                textBoxMood.Text = MoodEmptyText;
            }
            buttonSetMood.Visible = false;
            textBoxMood.ReadOnly = true;
            textBoxMood.ForeColor = Color.Gray;
        }

        #endregion

        #region Contacts

        private void dataGridViewContacts_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            CreateNewChat(new string[] { dataGridViewContacts.Rows[e.RowIndex].Tag.ToString() });
        }

        void skypeWrapper_UsersListed(SKYPE4COMLib.UserCollection users)
        {
            foreach(SKYPE4COMLib.User user in users)
            {
                var row = new DataGridViewRow();
                SetRow(row, user);
                DataGridViewFromHandle(user.Handle).Rows.Add(row);
            }

            SetDatagridScroll();
        }

        void skypeWrapper_UserUpdated(SKYPE4COMLib.User user)
        {
            DataGridViewRow row = GetRowByHandle(user.Handle);
            if (row == null) DataGridViewFromHandle(user.Handle).Rows.Add(row);
            SetRow(row, user);
            SortContacts();
            foreach (ChatForm chatForm in chatForms)
            {
                chatForm.UpdateUser(user);
            }
            callForm.UpdateUser(user);
            
        }

        private DataGridView DataGridViewFromHandle(string handle)
        {
            return skypeWrapper.IsServer(handle) ? dataGridViewS4PG : dataGridViewContacts;
        }

        private DataGridViewRow GetRowByHandle(string handle)
        {
            foreach (DataGridViewRow row in DataGridViewFromHandle(handle).Rows)
            {
                if (row.Tag.ToString() == handle) return row;
            }
            return null;
        }


        private void SetRow(DataGridViewRow row, SKYPE4COMLib.User user)
        {
            DataGridViewTextBoxCell statusIndexCell = new DataGridViewTextBoxCell();
            statusIndexCell.Value = (int)skypeWrapper.GetOnlineStatusFriendly(user);
            DataGridViewImageCell statusImageCell = new DataGridViewImageCell();
            statusImageCell.Value = SkypePXP.Properties.Resources.ResourceManager.GetObject(skypeWrapper.GetOnlineStatusFriendly(user).ToString());
            DataGridViewTextBoxCell displayNameCell = new DataGridViewTextBoxCell();
            displayNameCell.Value = skypeWrapper.GetDisplayName(user);
            DataGridViewTextBoxCell moodTextCell = new DataGridViewTextBoxCell();
            moodTextCell.Style.ForeColor = Color.LightGreen;
            moodTextCell.Value = user.MoodText;
            row.Tag = user.Handle;
            try
            {
                row.Cells[0] = statusIndexCell;
                row.Cells[1] = statusImageCell;
                row.Cells[2] = displayNameCell;
                row.Cells[3] = moodTextCell;
            }
            catch
            {
                row.Cells.AddRange(new DataGridViewCell[] { statusIndexCell, statusImageCell, displayNameCell, moodTextCell });
            }
        }

        private void dataGridView_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
            var dataGrid = (PLAYXPERT.Controls.PXPDataGridView)sender;
            SortContacts();
        }

        private void SortContacts()
        {
            dataGridViewContacts.Sort(dataGridViewContacts.Columns[0], System.ComponentModel.ListSortDirection.Ascending);
        }

        private string SelectedHandle
        {
            get
            {
                return FocusedDataGridView.SelectedRows[0].Tag.ToString();
            }
        }

        private DataGridView FocusedDataGridView
        {
            get
            {
                switch (yaTabControl1.SelectedIndex)
                {
                    case 0:
                        return dataGridViewContacts;
                    case 1:
                        return dataGridViewS4PG;
                }
                return null;
            }
        }

        private void SetDatagridScroll()
        {
            dataGridViewContacts.Height = (dataGridViewContacts.Rows.Count) * 19;
            dataGridViewS4PG.Height = (dataGridViewS4PG.Rows.Count) * 19;
            
        }


        #endregion

        #region Contacts Toolstrip

        private void startGameShareToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void blockToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            skypeWrapper.ToggleBlockedStatus(SelectedHandle);
        }

        private void callToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            skypeWrapper.PlaceCall(SelectedHandle);
        }

        private void sendIMToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string[] handles = new string[dataGridViewContacts.SelectedRows.Count];
            for (int i = 0; i < dataGridViewContacts.SelectedRows.Count; i++)
            {
                handles[i] = dataGridViewContacts.SelectedRows[i].Tag.ToString();
            }

            CreateNewChat(handles);
        }

        #endregion

        #region Hooking

        private void hook_Toggle(bool Enabled, string Key)
        {
            ToggleMute(!Enabled);
        }

        public void UpdateMuteDisplay(bool muted)
        {
            string mutedText = muted ? "Muted" : "UnMuted";
            callForm.pictureBoxMuteToggle.Image = (Image)SkypePXP.Properties.Resources.ResourceManager.GetObject(mutedText);
            callForm.labelMuteToggle.Text = mutedText;
        }

        public void ToggleMute(bool muted)
        {
            skypeWrapper.MuteToggle(muted);
        }

        #endregion

        #region iCore Misc

        void AutoEngine_EventTriggered(string eventName, IDictionary<string, string> eventData)
        {
            if (eventName == "Arcade.GameLaunched") directCapture = new DirectCapture(eventData["Name"]);
        }

        private void SkinControls()
        {
            iCore.GetSkinEngine().SkinControls(settingsPage, settingsPage.buttonClearMTK);
            iCore.GetSkinEngine().SkinControls(settingsPage, settingsPage.buttonClearPTT);
            iCore.GetSkinEngine().SkinControls(settingsPage, settingsPage.buttonClearSCK);
            iCore.GetSkinEngine().SkinControls(settingsPage, settingsPage.buttonSetKeyMTT);
            iCore.GetSkinEngine().SkinControls(settingsPage, settingsPage.buttonSetKeyPTT);
            iCore.GetSkinEngine().SkinControls(settingsPage, settingsPage.buttonSetKeySCK);
            iCore.GetSkinEngine().SkinControls(settingsPage, settingsPage.checkBoxHandleKeyMTT);
            iCore.GetSkinEngine().SkinControls(settingsPage, settingsPage.checkBoxHandleKeyPTT);
            iCore.GetSkinEngine().SkinControls(settingsPage, settingsPage.checkBoxHandleSCK);
            iCore.GetSkinEngine().SkinControls(this, comboBoxOnlineStatus);
            iCore.GetSkinEngine().SkinControls(callForm, callForm.listViewCallMembers);


            yaTabControl1.ForeColor = Color.LightGray;
            yaTabControl1.ActiveColor = Color.LightSlateGray;
            yaTabControl1.InactiveColor = mainBackColor;
            yaTabControl1.BorderColor = mainBackColor;
            yaTabControl1.BackColor = mainBackColor;
        }

        #endregion

        #region Mood TextBox

        private void textBoxMood_MouseDown(object sender, MouseEventArgs e)
        {
            buttonSetMood.Visible = true;
            textBoxMood.ReadOnly = false;
            textBoxMood.ForeColor = Color.Black;
            textBoxMood.Clear();
        }

        private void buttonSetMood_Click(object sender, EventArgs e)
        {
            UpdateMood();
        }

        private void textBoxMood_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                UpdateMood();
            }
        }

        #endregion

        void ScreenCap()
        {
            byte[] Buffer = directCapture.GetBytes(Format.Jpeg, 0);
            File.WriteAllBytes("C:\\Users\\Grimdoomer\\Desktop\\testesttest.wdp", Buffer);
        }

        private void dataGridViewCalls_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            ((DataGridView)sender).Rows[e.RowIndex].Selected = true;
        }

        private void splitContainer2_SplitterMoved(object sender, SplitterEventArgs e)
        {
            if (!callForm.Collapsed && callForm.groupBoxActiveCall.Visible)
            {
                foreach (Control control in callForm.groupBoxActiveCall.Controls)
                {
                    if (control.Location.Y + control.Height + 5 > e.SplitY)
                        control.Visible = false;
                    else
                        control.Visible = true;
                }
                if (!callForm.panelMuteToggle.Visible)
                {
                    callForm.TriggerCollapse();
                }
            }
        }

        private void yaTabControl1_TabIndexChanged(object sender, EventArgs e)
        {
            
        }

        //private void startGameShareSessionToolStripMenuItem_Click(object sender, EventArgs e)
        //{
        //    // Load GameShare
        //    ShareForm s = new ShareForm(core, skype.get_User(((PLAYXPERT.Controls.PXPDataGridView)dataGridView1).SelectedRows[0].Cells[1].Value.ToString()), Capture);
        //    hook.ScreenCap += new Hook.ScreenCapHandler(s.ScreenShotTaken);
        //    s.Show();

        //    // Loop
        //    while (s.Created)
        //        System.Windows.Forms.Application.DoEvents();

        //    // Reset Handler
        //    hook.ScreenCap += new Hook.ScreenCapHandler(ScreenCap);
        //}

    }
}